---
title: "Figure A.11"
output: 
---

# Figure A.11

# Who's to Blame? Postconflict Violence and Public Attitudes Towards Peace Agreements
# Wyer, Frank. 

#clear environment
```{r clear environment}
rm(list = ls())
```

# uncomment and set working directory to replication archive
# setwd("~/blame_replication")

# Uncomment to install packages if necessary
# install.packages("tidyverse")
# install.packages("estimatr")

#load packages
```{r}
library(tidyverse)
library(estimatr)
```

#read in data
```{r}
survey_clean <- read.csv("survey_clean.csv")
```

#outcome variable
#Q47 - most of the FARC are not dissidents (1 = totally disagree; 6 = totally disagree)

#reorder variable for interpretation so that higher value = increased stigma
```{r reorder variable}
survey_clean <- survey_clean %>%
mutate(farcstigma = case_when(
  Q47 == 1 ~ 6,
  Q47 == 2 ~ 5,
  Q47 == 3 ~ 4,
  Q47 == 4 ~ 3,
  Q47 == 5 ~ 2,
  Q47 == 6 ~ 1,
  TRUE ~ NA_real_
  )) # changing scale order
```

#scale farc stigma variable using control group mean and sd
```{r scale outcome}
survey_clean$farcstigma_scale <- (survey_clean$farcstigma - mean(survey_clean$farcstigma[survey_clean$treatment == "C"], na.rm = TRUE)) / sd(survey_clean$farcstigma[survey_clean$treatment == "C"], na.rm = TRUE)
```

#estimate models with farc stigma as outcome
```{r estimate models}
m_farcstigma_90 <- lm_lin(formula = farcstigma_scale ~ treatment, covariates = ~ Q15 + Q25 + urbandummy + engage_zscale + farc_presence + homratediff + factor(regionname), se_type = "HC2", data = survey_clean, alpha = 0.1)
m_farcstigma_95 <- lm_lin(formula = farcstigma_scale ~ treatment, covariates = ~ Q15 + Q25 + urbandummy + engage_zscale + farc_presence + homratediff + factor(regionname), se_type = "HC2", data = survey_clean, alpha = 0.05)
```

#save coefficients and CIs to dataframe
```{r coefficients dataframe}
farcstigma_df <- rbind(
data.frame(Treatment = "Postconflict Violence Treatment", Conf_Level = "95%", Outcome = "FARC Stigma Measure", Estimate = m_farcstigma_95$coefficients['treatmentT1'], Conf_Low = m_farcstigma_95$conf.low['treatmentT1'], Conf_High = m_farcstigma_95$conf.high['treatmentT1']), 
data.frame(Treatment = "Postconflict Violence Treatment", Conf_Level = "90%", Outcome = "FARC Stigma Measure", Estimate = m_farcstigma_90$coefficients['treatmentT1'], Conf_Low = m_farcstigma_90$conf.low['treatmentT1'], Conf_High = m_farcstigma_90$conf.high['treatmentT1']), 

data.frame(Treatment = "Government Culpability Treatment", Conf_Level = "95%", Outcome = "FARC Stigma Measure", Estimate = m_farcstigma_95$coefficients['treatmentT2A'], Conf_Low = m_farcstigma_95$conf.low['treatmentT2A'], Conf_High = m_farcstigma_95$conf.high['treatmentT2A']), 
data.frame(Treatment = "Government Culpability Treatment", Conf_Level = "90%", Outcome = "FARC Stigma Measure", Estimate = m_farcstigma_90$coefficients['treatmentT2A'], Conf_Low = m_farcstigma_90$conf.low['treatmentT2A'], Conf_High = m_farcstigma_90$conf.high['treatmentT2A']), 

data.frame(Treatment = "Rebel Culpability Treatment", Conf_Level = "95%", Outcome = "FARC Stigma Measure", Estimate = m_farcstigma_95$coefficients['treatmentT2B'], Conf_Low = m_farcstigma_95$conf.low['treatmentT2B'], Conf_High = m_farcstigma_95$conf.high['treatmentT2B']), 
data.frame(Treatment = "Rebel Culpability Treatment", Conf_Level = "90%", Outcome = "FARC Stigma Measure", Estimate = m_farcstigma_90$coefficients['treatmentT2B'], Conf_Low = m_farcstigma_90$conf.low['treatmentT2B'], Conf_High = m_farcstigma_90$conf.high['treatmentT2B'])
)
```

#set order of treatments in plot
```{r order treatments}
farcstigma_df$Treatment <- factor(farcstigma_df$Treatment, levels = c("Government Culpability Treatment", "Rebel Culpability Treatment", "Postconflict Violence Treatment"))
```

# plot models
```{r stigma plot}
farc_stigma_plot <- ggplot(farcstigma_df %>% pivot_wider(names_from = "Conf_Level", values_from = c(Estimate, Conf_Low, Conf_High)),  aes(y = Outcome, x = `Estimate_95%`, shape = Treatment)) +
  geom_vline(xintercept = 0, colour = gray(1/2), lty = 2) +
  scale_shape_manual(name = "", values = c(17, 15, 19), breaks = c("Postconflict Violence Treatment", "Rebel Culpability Treatment", "Government Culpability Treatment"), labels = function(x) str_wrap(x, width = 5)) +
  geom_linerange(aes(y = Outcome, xmin = `Conf_Low_90%`, xmax = `Conf_High_90%`), lwd = 1, position=position_dodge(.5)) + 
  geom_linerange(aes(y = Outcome, xmin = `Conf_Low_95%`, xmax = `Conf_High_95%`), lwd = 1/2, position=position_dodge(.5)) +
  geom_point(aes(y = Outcome, x = `Estimate_95%`), position=position_dodge(.5), size = 2.5) + 
  scale_y_discrete(labels = function(x) str_wrap(x, width = 15)) +
  guides(shape = guide_legend(byrow = TRUE)) + 
  xlim(-.25, .25) +
  labs(x = "", y = "", shape = "") +
  theme_bw() + 
  theme(legend.key.size = unit(2.5, 'lines'))
```
 